/*
 * main.c
 *
 *  Created on: Jul 28, 2013
 *      Author: lxzhu
 */

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

void onInit();
void onDraw();
void drawPolygon(float x,float y,float w,float h);

int main(int argc, char** argv){
	glutInit(&argc,argv);

	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
	glutCreateWindow("ShadeModel");
	glutDisplayFunc(onDraw);
	onInit();
	glutMainLoop();
	return 0;
}
void onInit(){
	glClearColor(1,1,1,1);
}
void onDraw(){
	glClear(GL_COLOR_BUFFER_BIT);
	glShadeModel(GL_SMOOTH);
	drawPolygon(-0.75,-0.75,0.5,0.5);
	glShadeModel(GL_FLAT);
	drawPolygon(0.25,0.25,0.5,0.5);

	glutSwapBuffers();
}

void drawPolygon(float x, float y,float width,float height){
	glBegin(GL_POLYGON);
	  glColor3f(0,0,1);
	  glVertex2f(x,y);
	  glColor3f(0,1,0);
	  glVertex2f(x+width,y);
	  glColor3f(1,0,0);
	  glVertex2f(x+width,y+height);
	  glColor3f(0,0,0);
	  glVertex2f(x,y+height);
	glEnd();
}
